package trash_pck;

import java.util.ArrayList;
import java.util.Iterator;

public class TestClass {
	
	public static void main(String[] args) {
		final int instanceCount = 5000000;
		ParentClass[] classes = new ParentClass[instanceCount];
		for(int i = 0; i < instanceCount ; i++) {
			classes[i] = new SonClass();
		}

		ArrayList<ParentClass> classes2 = new ArrayList<ParentClass>();
		for(int i = 0; i < instanceCount ; i++) {
			classes2.add(classes[i]);
		}
		
		for(int i = 0 ; i < 10 ; i++) {
			long start = System.currentTimeMillis();
			for(ParentClass son : classes)
					son.count();
			System.out.println("| Direct array call time = " + (System.currentTimeMillis() - start) + "ms.\t|");
			
			start = System.currentTimeMillis();
			for(ParentClass son : classes2.toArray(new ParentClass[instanceCount]))
					son.count();
			System.out.println("| ArrayList to array call time = " + (System.currentTimeMillis() - start) + "ms.\t|");
			
			start = System.currentTimeMillis();
			for(int j = 0; j < instanceCount ; j++)
					classes2.get(j).count();
			System.out.println("| Direct ArrayList call time = " + (System.currentTimeMillis() - start) + "ms.\t|");
			
			start = System.currentTimeMillis();
			for(ParentClass son : classes2)
					son.count();
			System.out.println("| Foreach ArrayList call time = " + (System.currentTimeMillis() - start) + "ms.\t|");
			
			start = System.currentTimeMillis();
			Iterator<ParentClass> it = classes2.iterator();
			while(it.hasNext())
					it.next().count();
			System.out.println("| Iterator ArrayList call time = " + (System.currentTimeMillis() - start) + "ms.\t|");
			
			System.out.println("|---------------------------------------|");
		}
	}

}
